package com.gitee.slowcreator.module.http.request.intface;

import com.gitee.slowcreator.http.annotation.*;
import com.gitee.slowcreator.http.enums.RequestType;
import com.gitee.slowcreator.http.exception.HttpRequestException;
import com.gitee.slowcreator.http.file.download.hutool.HutoolByteFileDownload;
import com.gitee.slowcreator.http.file.download.hutool.HutoolLocalFileDownload;
import com.gitee.slowcreator.http.file.download.okhttp.OkhttpByteFileDownload;
import com.gitee.slowcreator.http.file.download.okhttp.OkhttpLocalFileDownload;
import com.gitee.slowcreator.http.params.*;
import com.gitee.slowcreator.http.parser.json.JsonHttpReturnParser;

import java.util.Map;
import java.util.Set;

/**
 * @author zxw
 * @date 2023/1/7 上午11:46
 */
@HttpInterface(desc = "测试接口")
public interface ITestHttpRequest {

    /**
     * 测试get请求
     *
     * @param header
     * @param params
     * @param returnHeader
     * @return
     */
    @HttpClient(
            desc = "测试GET",
            url = "http://127.0.0.1:8080/annotationHttp/testGet",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000
    )
    ScReturn testGet(@HttpHeader Map<String, String> header,
                     @HttpParams Map<String, String[]> params,
                     @HttpReturnHeader Set<String> returnHeader);

    /**
     * 测试异步get请求
     *
     * @param header
     * @param params
     * @param returnHeader
     * @return
     */
    @HttpClient(
            desc = "测试GET",
            url = "http://127.0.0.1:8080/annotationHttp/testGet",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            isAsync = true
    )
    ScReturn testAsyncGet(@HttpHeader Map<String, String> header,
                          @HttpParams Map<String, String[]> params,
                          @HttpReturnHeader Set<String> returnHeader);

    /**
     * 测试超时
     *
     * @param header
     * @param params
     * @param returnHeader
     * @return
     */
    @HttpClient(
            desc = "测试GET",
            url = "http://127.0.0.1:8080/annotationHttp/testGet",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 1000,
            retry = @Retry(
                    open = true,
                    retryTimes = 3
            )
    )
    ScReturn testTimeout(@HttpHeader Map<String, String> header,
                         @HttpParams Map<String, String[]> params,
                         @HttpReturnHeader Set<String> returnHeader);

    /**
     * 测试post请求
     *
     * @param header
     * @param params
     * @param returnHeader
     * @param body
     * @return
     */
    @HttpClient(
            desc = "测试POST",
            url = "http://127.0.0.1:8080/annotationHttp/testPost",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.POST
    )
    ScReturn testPost(@HttpHeader Map<String, String> header,
                      @HttpParams Map<String, String[]> params,
                      @HttpReturnHeader Set<String> returnHeader,
                      ScBody body);

    /**
     * 测试put请求
     *
     * @param header
     * @param params
     * @param returnHeader
     * @param body
     * @return
     */
    @HttpClient(
            desc = "测试PUT",
            url = "http://127.0.0.1:8080/annotationHttp/testPut",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.PUT
    )
    ScReturn testPut(@HttpHeader Map<String, String> header,
                     @HttpParams Map<String, String[]> params,
                     @HttpReturnHeader Set<String> returnHeader,
                     ScBody body);

    /**
     * 测试delete请求
     *
     * @param header
     * @param params
     * @param returnHeader
     * @return
     */
    @HttpClient(
            desc = "测试DELETE",
            url = "http://127.0.0.1:8080/annotationHttp/testDelete",
            timeout = 10000,
            requestType = RequestType.DELETE
    )
    ScReturn testDelete(@HttpHeader Map<String, String> header,
                        @HttpParams Map<String, String[]> params,
                        @HttpReturnHeader Set<String> returnHeader);

    /**
     * 测试上传请求
     *
     * @param header
     * @param params
     * @param returnHeader
     * @param scMultipart
     * @return
     */
    @HttpClient(
            desc = "测试Upload",
            url = "http://127.0.0.1:8080/annotationHttp/testUpload",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.POST,
            isMultipart = true
    )
    ScReturn testUpload(@HttpHeader Map<String, String> header,
                        @HttpParams Map<String, String[]> params,
                        @HttpReturnHeader Set<String> returnHeader,
                        ScMultipart scMultipart);

    /**
     * 测试下载请求 使用 byte[] 接收数据
     *
     * @param header
     * @param params
     * @param returnHeader
     * @return
     */
    @HttpClient(
            desc = "测试DownloadByte",
            url = "http://127.0.0.1:8080/annotationHttp/testDownload",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.GET
    )
    ScReturn testDownloadByte(@HttpHeader Map<String, String> header,
                              @HttpParams Map<String, String[]> params,
                              @HttpReturnHeader Set<String> returnHeader);

    /**
     * 测试下载请求 文件直接写入本地
     *
     * @param header
     * @param params
     * @param returnHeader
     * @return
     */
    @HttpClient(
            desc = "测试DownloadWriteLocal",
            url = "http://127.0.0.1:8080/annotationHttp/testDownload",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.GET,
            download = true,
            downloadLocal = true,
            downloadLocalFilename = "/home/manjaro/test_file/annotation_http/test_down_local.jpg"
    )
    ScReturn testDownloadWriteLocal(@HttpHeader Map<String, String> header,
                                    @HttpParams Map<String, String[]> params,
                                    @HttpReturnHeader Set<String> returnHeader);

    /**
     * 测试json解析器
     *
     * @param header
     * @param params
     * @param returnHeader
     * @param body
     * @return
     */
    @HttpClient(
            desc = "测试POST",
            url = "http://127.0.0.1:8080/annotationHttp/testPost",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.POST,
            enhanceAfter = JsonHttpReturnParser.class
    )
    ScReturn testJsonParse(@HttpHeader Map<String, String> header,
                           @HttpParams Map<String, String[]> params,
                           @HttpReturnHeader Set<String> returnHeader,
                           ScBody body);

    /**
     * 测试ScUnionParams直接请求
     *
     * @param unionParams
     * @return
     */
    @HttpClient(
            desc = "测试UNION",
            url = "http://127.0.0.1:8080/annotationHttp/testPost",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.UNKNOWN
    )
    ScReturn testUnion(ScUnionParams unionParams);

    /**
     * 测试无注解请求
     *
     * @param header
     * @param params
     * @param returnHeader
     * @param body
     * @return
     */
    @HttpClient(
            desc = "测试NoAnnotation",
            url = "http://127.0.0.1:8080/annotationHttp/testPost",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.POST
    )
    ScReturn testNoAnnotation(ScHeader header,
                              ScParams params,
                              ScReturnHeader returnHeader,
                              ScBody body);

    /**
     * 测试url覆盖
     *
     * @param url
     * @return
     */
    @HttpClient(desc = "测试GET", url = "666")
    ScReturn testUrlChange(@HttpUrl String url);

    /**
     * 测试下载请求 文件直接写入本地
     *
     * @return
     */
    @HttpClient(
            desc = "测试新版文件下载",
            url = "https://i0.hdslb.com/bfs/archive/8a4c723d26489e3a08ef0497f2eb2f00335bcb29.png",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.GET,
            downloadHandle = @Download(
                    download = true,
                    useByte = true,
                    fileDownloadHandle = OkhttpByteFileDownload.class
            )
    )
    ScReturn testNewOkHttpDownloadByte();

    /**
     * 测试下载请求 文件直接写入本地
     *
     * @return
     */
    @HttpClient(
            desc = "测试新版文件下载",
            url = "https://i0.hdslb.com/bfs/archive/8a4c723d26489e3a08ef0497f2eb2f00335bcb29.png",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.GET,
            downloadHandle = @Download(
                    download = true,
                    useByte = false,
                    fileDownloadHandle = OkhttpLocalFileDownload.class
            )
    )
    ScReturn testNewOkHttpDownloadLocal();

    /**
     * 测试下载请求 文件直接写入本地
     *
     * @return
     */
    @HttpClient(
            desc = "测试新版文件下载",
            url = "https://i0.hdslb.com/bfs/archive/8a4c723d26489e3a08ef0497f2eb2f00335bcb29.png",
            failThrow = true,
            throwException = HttpRequestException.class,
            timeout = 10000,
            requestType = RequestType.GET,
            downloadHandle = @Download(
                    download = true,
                    useByte = true,
                    fileDownloadHandle = HutoolByteFileDownload.class
            )
    )
    ScReturn testNewHutoolDownloadByte();

    /**
     * 测试下载请求 文件直接写入本地
     * hutool下载大文件 需要设置 isAsync = true,否则还是需要等全部下载完才处理 不会边下载边写入,OkHttp可以不需要设置这一步实现边下载边写入
     * hutool设置 isAsync = true,并不会把这个请求变成异步请求,还是同步获得最后结果
     * OkHttp设置的话 会直接将当前调用变成异步请求处理
     *
     * @return
     */
    @HttpClient(
            desc = "测试新版文件下载",
            url = "https://i0.hdslb.com/bfs/archive/8a4c723d26489e3a08ef0497f2eb2f00335bcb29.png",
            failThrow = true,
            throwException = HttpRequestException.class,
            isAsync = true,
            timeout = 10000,
            requestType = RequestType.GET,
            downloadHandle = @Download(
                    download = true,
                    useByte = false,
                    fileDownloadHandle = HutoolLocalFileDownload.class
            )
    )
    ScReturn testNewHutoolDownloadLocal();
}
